{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "2017.7.17\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "import pandas as pd\n",
    "from pandas import Series, DataFrame\n",
    "from sklearn.model_selection import train_test_split\n",
    "import xgboost as xgb\n",
    "import time"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "train_data_set = pd.read_csv(\"feature/xgb_train_data.csv\")\n",
    "test_data_set = pd.read_csv(\"feature/xgb_test_data.csv\")\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "# 合并 训练数据 和 测试 数据，进行统一处理\n",
    "test_data_set['flag'] = -999\n",
    "train_test_data = pd.concat([train_data_set, test_data_set], axis=0)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>age</th>\n",
       "      <th>education_num</th>\n",
       "      <th>flag</th>\n",
       "      <th>hours_per_week</th>\n",
       "      <th>income</th>\n",
       "      <th>marital_status</th>\n",
       "      <th>race</th>\n",
       "      <th>relationship</th>\n",
       "      <th>sex</th>\n",
       "      <th>workclass</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>39</td>\n",
       "      <td>13</td>\n",
       "      <td>NaN</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>2</td>\n",
       "      <td>1</td>\n",
       "      <td>2</td>\n",
       "      <td>1</td>\n",
       "      <td>4</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>50</td>\n",
       "      <td>13</td>\n",
       "      <td>NaN</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>38</td>\n",
       "      <td>9</td>\n",
       "      <td>NaN</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>3</td>\n",
       "      <td>1</td>\n",
       "      <td>2</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>53</td>\n",
       "      <td>7</td>\n",
       "      <td>NaN</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>2</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>28</td>\n",
       "      <td>13</td>\n",
       "      <td>NaN</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>2</td>\n",
       "      <td>5</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   age  education_num  flag  hours_per_week  income  marital_status  race  \\\n",
       "0   39             13   NaN               1       0               2     1   \n",
       "1   50             13   NaN               0       0               1     1   \n",
       "2   38              9   NaN               1       0               3     1   \n",
       "3   53              7   NaN               1       0               1     2   \n",
       "4   28             13   NaN               1       0               1     2   \n",
       "\n",
       "   relationship  sex  workclass  \n",
       "0             2    1          4  \n",
       "1             1    1          2  \n",
       "2             2    1          1  \n",
       "3             1    1          1  \n",
       "4             5    0          1  "
      ]
     },
     "execution_count": 28,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "train_test_data.head(5)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 31,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "F:\\Program Files\\Anaconda3\\lib\\site-packages\\ipykernel\\__main__.py:15: SettingWithCopyWarning: \n",
      "A value is trying to be set on a copy of a slice from a DataFrame\n",
      "\n",
      "See the caveats in the documentation: http://pandas.pydata.org/pandas-docs/stable/indexing.html#indexing-view-versus-copy\n",
      "F:\\Program Files\\Anaconda3\\lib\\site-packages\\ipykernel\\__main__.py:16: SettingWithCopyWarning: \n",
      "A value is trying to be set on a copy of a slice from a DataFrame\n",
      "\n",
      "See the caveats in the documentation: http://pandas.pydata.org/pandas-docs/stable/indexing.html#indexing-view-versus-copy\n"
     ]
    }
   ],
   "source": [
    "# 合并 训练数据 和 测试 数据，进行统一处理\n",
    "test_data_set['flag'] = -999\n",
    "train_test_data = pd.concat([train_data_set, test_data_set], axis=0)\n",
    "\n",
    "category_val = [\"education_num\", \"marital_status\", \"relationship\", \"workclass\"]\n",
    "for val in category_val:\n",
    "    val_dummies = pd.get_dummies(train_test_data[val])\n",
    "    val_dummies.columns = [val + '_' + str(i) for i in range(val_dummies.shape[1])]\n",
    "    train_test_data.drop(val, axis=1, inplace=True)\n",
    "    train_test_data = pd.concat([train_test_data, val_dummies], axis=1)\n",
    "\n",
    "train_data = train_test_data[train_test_data.flag != -999]\n",
    "test_data = train_test_data[train_test_data.flag == -999]\n",
    "\n",
    "train_data.drop(\"flag\", axis=1, inplace=True)\n",
    "test_data.drop(\"flag\", axis=1, inplace=True)\n",
    "\n",
    "train_data.to_csv(\"feature/feature_train.csv\", index=None)\n",
    "test_data.to_csv(\"feature/feature_test.csv\", index=None)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 32,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "(32561, 43)\n",
      "(16281, 43)\n"
     ]
    }
   ],
   "source": [
    "print(train_data.shape)\n",
    "print(test_data.shape)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 33,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>age</th>\n",
       "      <th>hours_per_week</th>\n",
       "      <th>income</th>\n",
       "      <th>race</th>\n",
       "      <th>sex</th>\n",
       "      <th>education_num_0</th>\n",
       "      <th>education_num_1</th>\n",
       "      <th>education_num_2</th>\n",
       "      <th>education_num_3</th>\n",
       "      <th>education_num_4</th>\n",
       "      <th>...</th>\n",
       "      <th>relationship_5</th>\n",
       "      <th>workclass_0</th>\n",
       "      <th>workclass_1</th>\n",
       "      <th>workclass_2</th>\n",
       "      <th>workclass_3</th>\n",
       "      <th>workclass_4</th>\n",
       "      <th>workclass_5</th>\n",
       "      <th>workclass_6</th>\n",
       "      <th>workclass_7</th>\n",
       "      <th>workclass_8</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>39</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>...</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>50</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>...</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>38</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>...</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>3 rows × 43 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "   age  hours_per_week  income  race  sex  education_num_0  education_num_1  \\\n",
       "0   39               1       0     1    1              0.0              0.0   \n",
       "1   50               0       0     1    1              0.0              0.0   \n",
       "2   38               1       0     1    1              0.0              0.0   \n",
       "\n",
       "   education_num_2  education_num_3  education_num_4     ...       \\\n",
       "0              0.0              0.0              0.0     ...        \n",
       "1              0.0              0.0              0.0     ...        \n",
       "2              0.0              0.0              0.0     ...        \n",
       "\n",
       "   relationship_5  workclass_0  workclass_1  workclass_2  workclass_3  \\\n",
       "0             0.0          0.0          0.0          0.0          1.0   \n",
       "1             0.0          0.0          1.0          0.0          0.0   \n",
       "2             0.0          1.0          0.0          0.0          0.0   \n",
       "\n",
       "   workclass_4  workclass_5  workclass_6  workclass_7  workclass_8  \n",
       "0          0.0          0.0          0.0          0.0          0.0  \n",
       "1          0.0          0.0          0.0          0.0          0.0  \n",
       "2          0.0          0.0          0.0          0.0          0.0  \n",
       "\n",
       "[3 rows x 43 columns]"
      ]
     },
     "execution_count": 33,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "train_data.head(3)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "model_train_data = pd.read_csv(\"feature/feature_train.csv\")\n",
    "model_test_data = pd.read_csv(\"feature/feature_test.csv\")\n",
    "\n",
    "train_label = model_train_data[\"income\"]\n",
    "train_x = model_train_data.drop(\"income\", axis=1)\n",
    "\n",
    "test_label = model_test_data[\"income\"]\n",
    "test_x = model_test_data.drop(\"income\", axis=1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "offset is  22793\n"
     ]
    }
   ],
   "source": [
    "offset = round(0.7*train_x.shape[0])\n",
    "print(\"offset is \", str(offset))\n",
    "\n",
    "dtrain = xgb.DMatrix(train_x[:offset], label=train_label[:offset])\n",
    "dval = xgb.DMatrix(train_x[offset:], label=train_label[offset:])\n",
    "\n",
    "dtest = xgb.DMatrix(test_x)\n",
    "\n",
    "watchlist = [(dtrain, 'train')]\n",
    "\n",
    "#watchlist = [(dtrain, 'train'), (dval, 'val')]\n",
    "\n",
    "params = {'booster': 'gbtree',\n",
    "          'objective': 'binary:logistic',\n",
    "          'eta': 0.001,\n",
    "          'lambda': 30,\n",
    "          'gamma': 3,\n",
    "          'eval_metric': 'auc',\n",
    "          'max_depth': 6,\n",
    "          'subsample': 0.6,\n",
    "          'colsample_bytree': 0.6,\n",
    "          'min_child_weight': 3,\n",
    "          'seed': 1024,\n",
    "          'nthread': 8,\n",
    "         }\n",
    "\n",
    "#param_list = list(params.items())\n",
    "num_round = 259\n",
    "\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[0]\ttrain-auc:0.804695\n",
      "Will train until train-auc hasn't improved in 100 rounds.\n",
      "[1]\ttrain-auc:0.823594\n",
      "[2]\ttrain-auc:0.8299\n",
      "[3]\ttrain-auc:0.838425\n",
      "[4]\ttrain-auc:0.838612\n",
      "[5]\ttrain-auc:0.837589\n",
      "[6]\ttrain-auc:0.841515\n",
      "[7]\ttrain-auc:0.843114\n",
      "[8]\ttrain-auc:0.841324\n",
      "[9]\ttrain-auc:0.843074\n",
      "[10]\ttrain-auc:0.85312\n",
      "[11]\ttrain-auc:0.85347\n",
      "[12]\ttrain-auc:0.853047\n",
      "[13]\ttrain-auc:0.85323\n",
      "[14]\ttrain-auc:0.853464\n",
      "[15]\ttrain-auc:0.853648\n",
      "[16]\ttrain-auc:0.853386\n",
      "[17]\ttrain-auc:0.853711\n",
      "[18]\ttrain-auc:0.85377\n",
      "[19]\ttrain-auc:0.853715\n",
      "[20]\ttrain-auc:0.853541\n",
      "[21]\ttrain-auc:0.853442\n",
      "[22]\ttrain-auc:0.853523\n",
      "[23]\ttrain-auc:0.853249\n",
      "[24]\ttrain-auc:0.853094\n",
      "[25]\ttrain-auc:0.85313\n",
      "[26]\ttrain-auc:0.853246\n",
      "[27]\ttrain-auc:0.853254\n",
      "[28]\ttrain-auc:0.853166\n",
      "[29]\ttrain-auc:0.853255\n",
      "[30]\ttrain-auc:0.852691\n",
      "[31]\ttrain-auc:0.852736\n",
      "[32]\ttrain-auc:0.852726\n",
      "[33]\ttrain-auc:0.858756\n",
      "[34]\ttrain-auc:0.858432\n",
      "[35]\ttrain-auc:0.858387\n",
      "[36]\ttrain-auc:0.858365\n",
      "[37]\ttrain-auc:0.858372\n",
      "[38]\ttrain-auc:0.858889\n",
      "[39]\ttrain-auc:0.858798\n",
      "[40]\ttrain-auc:0.857845\n",
      "[41]\ttrain-auc:0.858205\n",
      "[42]\ttrain-auc:0.858503\n",
      "[43]\ttrain-auc:0.858621\n",
      "[44]\ttrain-auc:0.858782\n",
      "[45]\ttrain-auc:0.859009\n",
      "[46]\ttrain-auc:0.858392\n",
      "[47]\ttrain-auc:0.858081\n",
      "[48]\ttrain-auc:0.858089\n",
      "[49]\ttrain-auc:0.858055\n",
      "[50]\ttrain-auc:0.858191\n",
      "[51]\ttrain-auc:0.858095\n",
      "[52]\ttrain-auc:0.859449\n",
      "[53]\ttrain-auc:0.859473\n",
      "[54]\ttrain-auc:0.858972\n",
      "[55]\ttrain-auc:0.858954\n",
      "[56]\ttrain-auc:0.85867\n",
      "[57]\ttrain-auc:0.858681\n",
      "[58]\ttrain-auc:0.858694\n",
      "[59]\ttrain-auc:0.858521\n",
      "[60]\ttrain-auc:0.858425\n",
      "[61]\ttrain-auc:0.858434\n",
      "[62]\ttrain-auc:0.858189\n",
      "[63]\ttrain-auc:0.858542\n",
      "[64]\ttrain-auc:0.858708\n",
      "[65]\ttrain-auc:0.858596\n",
      "[66]\ttrain-auc:0.858428\n",
      "[67]\ttrain-auc:0.858195\n",
      "[68]\ttrain-auc:0.858625\n",
      "[69]\ttrain-auc:0.858518\n",
      "[70]\ttrain-auc:0.858424\n",
      "[71]\ttrain-auc:0.858261\n",
      "[72]\ttrain-auc:0.858184\n",
      "[73]\ttrain-auc:0.85824\n",
      "[74]\ttrain-auc:0.858258\n",
      "[75]\ttrain-auc:0.858332\n",
      "[76]\ttrain-auc:0.858408\n",
      "[77]\ttrain-auc:0.858546\n",
      "[78]\ttrain-auc:0.858603\n",
      "[79]\ttrain-auc:0.858543\n",
      "[80]\ttrain-auc:0.8586\n",
      "[81]\ttrain-auc:0.858112\n",
      "[82]\ttrain-auc:0.858076\n",
      "[83]\ttrain-auc:0.858072\n",
      "[84]\ttrain-auc:0.858205\n",
      "[85]\ttrain-auc:0.858101\n",
      "[86]\ttrain-auc:0.858095\n",
      "[87]\ttrain-auc:0.858554\n",
      "[88]\ttrain-auc:0.85859\n",
      "[89]\ttrain-auc:0.858736\n",
      "[90]\ttrain-auc:0.858642\n",
      "[91]\ttrain-auc:0.858691\n",
      "[92]\ttrain-auc:0.858818\n",
      "[93]\ttrain-auc:0.859026\n",
      "[94]\ttrain-auc:0.859055\n",
      "[95]\ttrain-auc:0.858848\n",
      "[96]\ttrain-auc:0.858803\n",
      "[97]\ttrain-auc:0.858892\n",
      "[98]\ttrain-auc:0.858964\n",
      "[99]\ttrain-auc:0.859055\n",
      "[100]\ttrain-auc:0.859933\n",
      "[101]\ttrain-auc:0.859916\n",
      "[102]\ttrain-auc:0.859913\n",
      "[103]\ttrain-auc:0.86002\n",
      "[104]\ttrain-auc:0.859805\n",
      "[105]\ttrain-auc:0.859734\n",
      "[106]\ttrain-auc:0.859758\n",
      "[107]\ttrain-auc:0.859714\n",
      "[108]\ttrain-auc:0.859684\n",
      "[109]\ttrain-auc:0.859693\n",
      "[110]\ttrain-auc:0.86029\n",
      "[111]\ttrain-auc:0.860815\n",
      "[112]\ttrain-auc:0.860879\n",
      "[113]\ttrain-auc:0.860843\n",
      "[114]\ttrain-auc:0.860877\n",
      "[115]\ttrain-auc:0.861007\n",
      "[116]\ttrain-auc:0.860986\n",
      "[117]\ttrain-auc:0.860923\n",
      "[118]\ttrain-auc:0.860887\n",
      "[119]\ttrain-auc:0.860943\n",
      "[120]\ttrain-auc:0.860925\n",
      "[121]\ttrain-auc:0.860577\n",
      "[122]\ttrain-auc:0.86074\n",
      "[123]\ttrain-auc:0.860737\n",
      "[124]\ttrain-auc:0.860743\n",
      "[125]\ttrain-auc:0.861081\n",
      "[126]\ttrain-auc:0.860915\n",
      "[127]\ttrain-auc:0.860567\n",
      "[128]\ttrain-auc:0.860681\n",
      "[129]\ttrain-auc:0.860679\n",
      "[130]\ttrain-auc:0.860521\n",
      "[131]\ttrain-auc:0.860368\n",
      "[132]\ttrain-auc:0.860399\n",
      "[133]\ttrain-auc:0.860938\n",
      "[134]\ttrain-auc:0.861002\n",
      "[135]\ttrain-auc:0.860674\n",
      "[136]\ttrain-auc:0.860806\n",
      "[137]\ttrain-auc:0.860928\n",
      "[138]\ttrain-auc:0.860954\n",
      "[139]\ttrain-auc:0.860943\n",
      "[140]\ttrain-auc:0.861045\n",
      "[141]\ttrain-auc:0.861067\n",
      "[142]\ttrain-auc:0.861037\n",
      "[143]\ttrain-auc:0.861117\n",
      "[144]\ttrain-auc:0.861133\n",
      "[145]\ttrain-auc:0.861133\n",
      "[146]\ttrain-auc:0.861152\n",
      "[147]\ttrain-auc:0.860721\n",
      "[148]\ttrain-auc:0.86073\n",
      "[149]\ttrain-auc:0.860586\n",
      "[150]\ttrain-auc:0.860513\n",
      "[151]\ttrain-auc:0.860825\n",
      "[152]\ttrain-auc:0.861127\n",
      "[153]\ttrain-auc:0.861152\n",
      "[154]\ttrain-auc:0.861121\n",
      "[155]\ttrain-auc:0.86113\n",
      "[156]\ttrain-auc:0.861611\n",
      "[157]\ttrain-auc:0.861661\n",
      "[158]\ttrain-auc:0.861621\n",
      "[159]\ttrain-auc:0.861671\n",
      "[160]\ttrain-auc:0.861453\n",
      "[161]\ttrain-auc:0.861474\n",
      "[162]\ttrain-auc:0.861514\n",
      "[163]\ttrain-auc:0.861528\n",
      "[164]\ttrain-auc:0.861484\n",
      "[165]\ttrain-auc:0.861499\n",
      "[166]\ttrain-auc:0.861534\n",
      "[167]\ttrain-auc:0.861538\n",
      "[168]\ttrain-auc:0.861537\n",
      "[169]\ttrain-auc:0.861529\n",
      "[170]\ttrain-auc:0.861424\n",
      "[171]\ttrain-auc:0.861564\n",
      "[172]\ttrain-auc:0.861758\n",
      "[173]\ttrain-auc:0.861781\n",
      "[174]\ttrain-auc:0.861691\n",
      "[175]\ttrain-auc:0.861723\n",
      "[176]\ttrain-auc:0.861768\n",
      "[177]\ttrain-auc:0.861757\n",
      "[178]\ttrain-auc:0.861736\n",
      "[179]\ttrain-auc:0.861734\n",
      "[180]\ttrain-auc:0.861746\n",
      "[181]\ttrain-auc:0.861735\n",
      "[182]\ttrain-auc:0.86157\n",
      "[183]\ttrain-auc:0.861588\n",
      "[184]\ttrain-auc:0.861564\n",
      "[185]\ttrain-auc:0.861485\n",
      "[186]\ttrain-auc:0.86146\n",
      "[187]\ttrain-auc:0.861456\n",
      "[188]\ttrain-auc:0.861382\n",
      "[189]\ttrain-auc:0.861286\n",
      "[190]\ttrain-auc:0.861298\n",
      "[191]\ttrain-auc:0.861322\n",
      "[192]\ttrain-auc:0.861336\n",
      "[193]\ttrain-auc:0.861328\n",
      "[194]\ttrain-auc:0.861259\n",
      "[195]\ttrain-auc:0.861271\n",
      "[196]\ttrain-auc:0.861259\n",
      "[197]\ttrain-auc:0.861293\n",
      "[198]\ttrain-auc:0.861289\n",
      "[199]\ttrain-auc:0.861289\n",
      "[200]\ttrain-auc:0.861275\n",
      "[201]\ttrain-auc:0.861339\n",
      "[202]\ttrain-auc:0.861397\n",
      "[203]\ttrain-auc:0.861407\n",
      "[204]\ttrain-auc:0.861398\n",
      "[205]\ttrain-auc:0.861417\n",
      "[206]\ttrain-auc:0.861522\n",
      "[207]\ttrain-auc:0.861502\n",
      "[208]\ttrain-auc:0.861495\n",
      "[209]\ttrain-auc:0.861549\n",
      "[210]\ttrain-auc:0.861579\n",
      "[211]\ttrain-auc:0.861687\n",
      "[212]\ttrain-auc:0.861738\n",
      "[213]\ttrain-auc:0.861767\n",
      "[214]\ttrain-auc:0.861836\n",
      "[215]\ttrain-auc:0.861829\n",
      "[216]\ttrain-auc:0.861835\n",
      "[217]\ttrain-auc:0.861816\n",
      "[218]\ttrain-auc:0.862003\n",
      "[219]\ttrain-auc:0.862089\n",
      "[220]\ttrain-auc:0.862109\n",
      "[221]\ttrain-auc:0.862113\n",
      "[222]\ttrain-auc:0.861926\n",
      "[223]\ttrain-auc:0.861938\n",
      "[224]\ttrain-auc:0.861924\n",
      "[225]\ttrain-auc:0.862144\n",
      "[226]\ttrain-auc:0.862158\n",
      "[227]\ttrain-auc:0.862017\n",
      "[228]\ttrain-auc:0.862032\n",
      "[229]\ttrain-auc:0.862108\n",
      "[230]\ttrain-auc:0.862079\n",
      "[231]\ttrain-auc:0.862071\n",
      "[232]\ttrain-auc:0.862079\n",
      "[233]\ttrain-auc:0.862088\n",
      "[234]\ttrain-auc:0.862035\n",
      "[235]\ttrain-auc:0.862047\n",
      "[236]\ttrain-auc:0.862055\n",
      "[237]\ttrain-auc:0.862026\n",
      "[238]\ttrain-auc:0.862025\n",
      "[239]\ttrain-auc:0.861955\n",
      "[240]\ttrain-auc:0.861885\n",
      "[241]\ttrain-auc:0.861869\n",
      "[242]\ttrain-auc:0.861891\n",
      "[243]\ttrain-auc:0.861885\n",
      "[244]\ttrain-auc:0.861687\n",
      "[245]\ttrain-auc:0.86162\n",
      "[246]\ttrain-auc:0.861591\n",
      "[247]\ttrain-auc:0.861447\n",
      "[248]\ttrain-auc:0.861526\n",
      "[249]\ttrain-auc:0.861594\n",
      "[250]\ttrain-auc:0.861566\n",
      "[251]\ttrain-auc:0.861545\n",
      "[252]\ttrain-auc:0.861637\n",
      "[253]\ttrain-auc:0.861685\n",
      "[254]\ttrain-auc:0.861681\n",
      "[255]\ttrain-auc:0.861668\n",
      "[256]\ttrain-auc:0.861721\n",
      "[257]\ttrain-auc:0.861712\n",
      "[258]\ttrain-auc:0.861669\n"
     ]
    }
   ],
   "source": [
    "model = xgb.train(params, dtrain, num_boost_round=num_round, evals=watchlist, early_stopping_rounds=100)\n",
    "model.save_model('model/xgb.model')\n",
    "print(\"best best_ntree_limit\", model.best_ntree_limit)"
   ]
  }
 ],
 "metadata": {
  "anaconda-cloud": {},
  "kernelspec": {
   "display_name": "Python [conda root]",
   "language": "python",
   "name": "conda-root-py"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.5.2"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 1
}
